﻿@using OSBLE.Models.Users
@using OSBLEPlus.Logic.DomainObjects.ActivityFeeds
@{
    string rootId = ViewBag.RootId;
    ViewBag.Title = string.Format("Details - {0}", rootId);
    UserProfile currentUser = ViewBag.CurrentUser;
    ViewBag.ShowDetails = true;
    var currentCourseUsers = ViewBag.CurrentCourseUsers;
    string EnableCustomPostVisibility = ViewBag.EnableCustomPostVisibility;

    string urlReferrer = Request != null && Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : "";
    bool interventionReferrer = urlReferrer.Contains("Intervention");    
}

<script type="text/javascript" src="@Url.Content("~/signalr/hubs")"></script>
<script type="text/javascript">
    var vm;
    $(document).ready(function () {
        vm = new DetailsViewModel("@currentUser.FullName", @currentUser.ID, "@rootId");
        ko.applyBindings(vm);
        vm.RequestUpdate();

        $("#previous-url").val(GetPreviousUrl());        
        ShowBackToSuggestions();
    });    
</script>

<script type="text/javascript">
    /*START Autocomplete block*/
    //TODO: need to re-build the url/<a/> tags for @@name and #hashtag.
    var userNames = []
    var userIds = [];

    //we need to get hashtags from the hashtag table and populate it like names are populated.
    //we also need to add hashtags to the table if there are no matches so others will see hashtags they've seen already.
    var hashtags = [];
    @{
        if (null != ViewBag.HashTags)
        {
            foreach(string hashTag in ViewBag.HashTags)
            {
                @:hashtags.push("@hashTag");
            }
        }
        if (null != currentCourseUsers)
        {
            foreach (var userProfile in currentCourseUsers)
            {
                @:userNames.push("@userProfile.FirstName" + "@userProfile.LastName");
                @:userIds.push("@userProfile.ID");
            }
        }
    }

    localStorage['UserNames'] = userNames;
    localStorage['UserIds'] = userIds;

    $(document).on("focus", "textarea", function () {
        $(this).atwho({
            at: "@@",
            data: userNames,
            insertTpl: "@@${name}", //insert template i.e. what is inserted into the textarea
        });

        $(this).atwho({
            at: "#",
            data: hashtags
        });
    });
</script>

@*Back to Suggestion link working inconsistently, disabled for now*@
@*@if (interventionReferrer)
{
    <a href="@urlReferrer" class="btn btn-primary"><span class="glyphicon glyphicon-arrow-left intervention-info"></span> Back to Suggestion</a>
}
else
{
    <a href="@urlReferrer" class="btn btn-primary" id="suggestion-back-link" style="display: none;"><span class="glyphicon glyphicon-arrow-left intervention-info"></span> Back to Suggestion</a>
}*@ 

<section id="Details" data-bind="foreach: items">
    @Html.Partial("Feed/_FeedItems")
</section>

<div id="visibility-dialog" title="Post Visibility:" hidden="hidden"></div>

@if (ViewBag.IsInstructor || ViewBag.CanGrade)
{   
    <input type="hidden" id="can-grade" value="true" />
}
<input type="hidden" id="current-user-id" value="@currentUser.ID" />
<input type="hidden" id="enable-pm" value="@EnableCustomPostVisibility" />
